變數 (variables)
是否為同一個物件 (object)
。True
False
littleMing_cart = ["豬腳", "佛跳牆", "香腸"]
grandma_cart = ["豬腳", "佛跳牆", "香腸"]
littleMing_cart = ["豬腳", "佛跳牆", "香腸"]
grandma_cart = ["豬腳", "佛跳牆", "香腸"]
print(littleMing_cart is grandma_cart)
False
但假如有先讓兩個物件相等,像這樣:
littleMing_cart = ["豬腳", "佛跳牆", "香腸"]
grandma_cart = ["豬腳", "佛跳牆", "香腸"]
littleMing_cart = grandma_cart
print(littleMing_cart is grandma_cart)
==
是一種比較運算符 (comparison operators)
在 Python 中有六種比較運算符,分別是:
<
小於<=
小於等於>
大於>=
大於等於==
相等!=
不相等==
是比較兩個值,如果左邊的值等於右邊的值,則回傳值為 True
,否則回傳為 False
littleMing_cart = ["豬腳", "佛跳牆", "香腸"]
grandma_cart = ["豬腳", "佛跳牆", "香腸"]
print(littleMing_cart == grandma_cart)
True
is
的不同, ==
是物件裡面的值比較,is
是兩個物件是否有相等參考資料
w3schools -Python is Keyword